package com.jake.spring.mvc.controller;

import com.jake.spring.mvc.exception.MyException;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("exception")
public class ExceptionController {

    @GetMapping("{uid}")
    public String getException(@PathVariable int uid) {
        if (uid < 1) {
            throw new MyException("uid小于1");
        }
        return Base64Utils.encodeToUrlSafeString(Integer.toString(uid).getBytes());
    }
}
